﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.AutomaticInterferenceVolumeCreation.CApAutomaticInterferenceVolumeCreationCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.AutomaticInterferenceVolumeCreation.Resources;
using System.Collections;
using System.Windows;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.AutomaticInterferenceVolumeCreation;

public class CApAutomaticInterferenceVolumeCreationCmd : TxButtonCommand
{
  private TxWindow aivcWindow;
  private CApAutomaticInterferenceVolumeCreationEnabler enabler;

  public CApAutomaticInterferenceVolumeCreationCmd()
  {
    this.enabler = new CApAutomaticInterferenceVolumeCreationEnabler();
  }

  public virtual bool Licensed => TxCommandLicenser.AutomaticInterferenceVolumeCreationLicense;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.enabler;

  public virtual string Category => AIVCResources.AIVC_CATEGORY;

  public virtual string Description => AIVCResources.AIVC_DESCRIPTION;

  public virtual string Bitmap => "AutomaticInterferenceVolumeCreation.Resources.AIVCCmdIcon.bmp";

  public virtual string LargeBitmap
  {
    get => "AutomaticInterferenceVolumeCreation.Resources.AIVCCmdIcon_LARGE.png";
  }

  public virtual string Tooltip => AIVCResources.AIVC_TOOLTIP;

  public virtual string Name => AIVCResources.AIVC_NAME;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("AutomaticInterference");

  public virtual void Execute(object cmdParams)
  {
    if (!TxTcUtilities.IsTcAnyPlatform)
      this.CheckCustomization();
    this.aivcWindow = (TxWindow) new CUIAutomaticInterferenceVolumeCreationDlg();
    ((Window) this.aivcWindow).Show();
  }

  private void CheckCustomization()
  {
    string aivcName = AIVCResources.AIVC_NAME;
    string str = "";
    if (TxApplication.PlatformType == 1 && !this.HasFieldInCustForClass("PmInterferenceVolume", "simulationInfo"))
      str = AIVCResources.AIVC_IV_MISSING_SIMULATIONINFO_CUSTOMIZATION_FIELD;
    if (!this.HasFieldInCustForClass("SweptVolume", "clearance"))
    {
      if (str != "")
        str += "\n";
      str += AIVCResources.AIVC_SV_MISSING_CLEARANCE_CUSTOMIZATION_FIELD;
    }
    if (!(str != ""))
      return;
    int num = (int) TxMessageBox.ShowModal(str, aivcName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }

  private bool HasFieldInCustForClass(string className, string fieldName)
  {
    ArrayList allFields = TxApplication.ActiveDocument.PlatformGlobalServicesProvider.GetTypeMetaData(className).AllFields;
    bool flag = false;
    foreach (TxPlanningTypeFieldData planningTypeFieldData in allFields)
    {
      if (planningTypeFieldData.Name == fieldName)
        flag = true;
    }
    return flag;
  }
}
